local csar = CSAR:New("blue", "Downed Pilot", "Akatsuki")
csar.immortalcrew = true
csar.invisiblecrew = false

csar:__Start(5)

csar.allowDownedPilotCAcontrol = false
csar.allowFARPRescue = true
csar.FARPRescueDistance = 3000
csar.autosmoke = true
csar.autosmoke = 1000
csar.coordtype = 2
csar.csarOncrash = true
csar.enableForAI = false
csar.pilotRuntoExtractPoint = true
csar.extractDistance = 500
csar.loadDistance = 100
csar.mashprefix = { "MASH" }
csar.max_units = 6
csar.messageTime = 20
csar.smokecolor = 4
csar.useprefix = true
csar.csarPrefix = { "BLUE", "Phase", "Khaimah", "Fujairah", "CVN", "KUZ" }
csar.limitmaxdownedpilots = true
csar.maxdownedpilots = 10
csar.approachdist_far = 5000
csar.approachdist_near = 3000
csar.pilotmustopendoors = false
csar.suppressmessages = true
csar.rescuehoverdistance = 20
csar.rescuehoverheight = 10
csar.topmenuname = "战斗搜寻与救援任务"
csar.PilotWeight = 80

function csar:OnAfterPilotDown(from, event, to, spawnedgroup, frequency, groupname, coordinates_text)
    MessageToAll("友军飞行员成功跳伞，需要撤离！", 10, "CSAR")
    SOUND_EXTRACTIONCALL:ToAll()
end

function csar:OnAfterApproach(from, event, to, heliname, groupname)
    local group = GROUP:FindByName(heliname)
    MESSAGE:New("你正在接近一名友方飞行员", 10, "CSAR", false):ToGroup(group)
end

function csar:OnAfterBoarded(from, event, to, heliname, Woundedgroupname, description)
    local group = GROUP:FindByName(heliname)
    MESSAGE:New("飞行员已经登舱", 10, "CSAR", false):ToGroup(group)
    SOUND_15SEC:ToAll()
end

function csar:OnAfterRescued(from, event, to, heliunit, heliname, pilotssaved)
    MessageToAll(heliunit:GetPlayerName() .. "成功救援了" .. tostring(pilotssaved) .. "个飞行员。", 10, "CSAR")
    SOUND_HELORTB:ToAll()
    
    local ucid = NET:New():GetPlayerUCID(nil, heliunit:GetPlayerName())
    local url = "http://localhost:8079/api/player/csar"
    local params = "ucid=" .. ucid
    local response = SendRequest(url, params)
    MESSAGE:New(response, 10, "战绩", false):ToUnit(heliunit)
end
